<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
	#manage-form{
		display: table;
	}
	.table-row{
	
		display: table-row;
	}
	.table-row>*{
		display: table-cell;
		margin-left: 20px;
		margin-top: 5px;
	}

</style>
<script type="text/javascript">
  $.ajax({
	  type:"POST",
	  url:"company",
	  success:function(data){
		  var content = data;
		  $("#companyname").append(data);
	  }
  })
</script>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div class="table-row">
				<label for="jobcode">公司名称:</label> 
				<input type="text" class="ui-input" name="tradename" id="companyname" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">用户编码:</label> 
				<input type="text" class="ui-input" name="tradename" id="usercode" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">用户名:</label> 
				<input type="text" class="ui-input" name="tradename" id="username" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">密码:</label> 
				<input type="text" class="ui-input" name="tradename" id="password" >
			</div>
			<div class="table-row">
				<label for="jobcode">邮箱:</label> 
				<input type="text" class="ui-input" name="tradename" id="email" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">手机:</label> 
				<input type="text" class="ui-input" name="tradename" id="mobile" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">微信</label> 
				<input type="text" class="ui-input" name="tradename" id="weixin" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">qq:</label> 
				<input type="text" class="ui-input" name="tradename" id="qq" disabled="disabled">
			</div>
			<div class="table-row">
				<label for="jobcode">备注:</label> 
				<input type="text" class="ui-input" name="tradename" id="remark" disabled="disabled">
			</div>
			<!-- <div class="table-row">
				<label for="jobcode">创建时间:</label> 
				<input type="text" class="ui-input" name="tradename" id="createtime">
			</div>
			<div class="table-row">
				<label for="jobcode">修改时间:</label> 
				<input type="text" class="ui-input" name="tradename" id="updatetime">
			</div> -->
			<div class="table-row">
				<label for="jobcode">使用标志:</label> 
				<div id="endFlag" style="padding-top: 9px;">
					<input  style="margin-top: 15px;" class="switch-simple-3" id="switch_endFlag" type="checkbox" ><label for="switch_endFlag" class="green"></label>
				</div>
			</div>
		</form>
	</div>

	<script type="text/javascript">
var api=frameElement.api;
var operate=api.data.operate;
var rowid=api.data.rowid;
var rowdata=api.data.rowdata;
var CallBack=api.data.callback;
$(function(){
	initPopBtns();
	if(operate=="edit"){
		$("#companyname").val(rowdata.companyname);
		$("#usercode").val(rowdata.usercode);
		$("#username").val(rowdata.username);
		$("#password").val(rowdata.password);
		$("#email").val(rowdata.email);
		$("#mobile").val(rowdata.mobile);
		$("#weixin").val(rowdata.weixin);
		$("#qq").val(rowdata.qq);
		$("#remark").val(rowdata.remark);
		$("#endFlag").html(rowdata.active);
	}
})
function initPopBtns() {
	var btnname = "add" == operate ? ["保存", "关闭"] : ["确定", "取消"];
	api.button({
		id: "confirm",
		name: btnname[0],
		focus: true,
		callback: function(e) {
			var active;
			var companyname=$("#companyname").val();
			var usercode=$("#usercode").val();
			var username=$("#username").val();
			var password=$("#password").val();
			var email=$("#email").val();
			var mobile=$("#mobile").val();
			var weixin=$("#weixin").val();
			var qq=$("#qq").val();
			var remark=$("#remark").val();
			var activeFlag = $("#endFlag input").prop("checked");
			if(activeFlag == true){
				active=1;
			}
			else{
				active=0;
			}
			if(operate=="add"){
				$.ajax({
					url : '/editEmploy?oper=add',
					type : 'POST',
					dataType : "json",
					data: {
						"companyname":companyname,//记得改这个
						"usercode":usercode,
						"username":username,
						"password":password,
						"email":email,
						"mobile":mobile,
						"weixin":weixin,
						"qq":qq,
						"remark":remark,
						"active":active
					},
					async : false,
					success : function(data) {
						if(data.status==200){
							parent.Public.tips({
								content: "添加成功"
							})
							CallBack();
						}else{
							if(data.status==400){
								parent.Public.tips({
									type:1,
									content: "用戶編碼已經存在"
								})
							}
							else{
							parent.Public.tips({
								type:1,
								content: "添加失败:"+data.msg
							})
							}
						}
					}
				});
			}else{
				$.ajax({
					url:encodeURI("/editEmploy?oper=edit"),
					type:"POST",
					data:{
						"id":rowid,
						"companyname":companyname,
						"username":username,
						"usercode":usercode,
						"password":password,
						"email":email,
						"mobile":mobile,
						"weixin":weixin,
						"qq":qq,
						"remark":remark,
						"active":active
					},
					async : false,//同步,坑爹啊。。
					success:function(data){
						if(data.status==200){
							parent.Public.tips({
								content: "修改成功"
							})
							CallBack();
						}
						else if (data.status==500){
							parent.Public.tips({
								type:1,
								content: "修改失败,该字段已被引用"
							})
						}
						else{
							parent.Public.tips({
								type:1,
								content: "修改失败,用戶編碼已經存在"
							})
						}		
					}
				});
			}
		}
	}, {
		id: "cancel",
		name: btnname[1]
	})
}



</script>
</body>
</html>